package com.msl.debezium.common;

import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

public class Msg<T> implements Serializable {

    private static final long serialVersionUID = 6774402718806640830L;

    @ApiModelProperty(notes = "返回代码 200-成功 400-失败 401-未授权 404-请求未找到 500-服务器错误", example = "200")
    private Integer code;
    @ApiModelProperty(notes = "返回错误消息", example = "请求成功/失败")
    private String message;
    @ApiModelProperty(notes = "返回JSON数据", example = "")
    private T data;

    public Msg(){
        this.code = 200;
        this.message = ResultCodeEnum.SUCCESS.getMessage();
    }

    public Msg(T data){
        this.code = 200;
        this.data = data;
    }

    public Msg(ResultCodeEnum resultCodeEnum, String message){
        this.code = resultCodeEnum.getCode();
        this.message = message;
    }

    public static Msg ok (){
        return new Msg();
    }

    public static<T> Msg<T> ok (T data){
        return new Msg(data);
    }

    public static<T> Msg<T> err (ResultCodeEnum resultCodeEnum, String message){
        return new Msg<T>(resultCodeEnum, message);
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

}
